package cn.bytets.rpc.api.code;


/**
 * Netty ByteBuf接口类,主要是这里没有引用Netty包,所以使用不到ByteBuf这个类,
 * 而ChannelByteBuf则是复制了ByteBuf这个方法
 */
public interface ChannelByteBuf extends Comparable<ChannelByteBuf> {

    /**
     * Returns the {@code writerIndex} of this buffer.
     */
    int writerIndex();

    void writeIndex(int index);

    void writeBytes(byte[] src);

    /**
     * Transfers the specified source array's data to this buffer starting at
     * the current {@code writerIndex} and increases the {@code writerIndex} by
     * the number of the transferred bytes (= {@code length}).
     *
     * @param index  the first index of the source
     * @param length the number of bytes to transfer
     * @throws IndexOutOfBoundsException if the specified {@code srcIndex} is
     *                                   less than {@code 0}, if {@code srcIndex
     *                                   + length} is greater than {@code
     *                                   src.length}, or if {@code length} is
     *                                   greater than {@code this.writableBytes}
     */
    void writeBytes(byte[] src, int index, int length);


    /**
     * Sets the specified byte at the current {@code writerIndex} and increases
     * the {@code writerIndex} by {@code 1} in this buffer. The 24 high-order
     * bits of the specified value are ignored.
     *
     * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less
     *                                   than {@code 1}
     */
    void writeByte(int value);

    void writeInt(int value);

    void markReaderIndex();

    int readerIndex();

    void readBytes(byte[] dist,int start,int len);

    void readBytes(byte[] src);

    int capacity();

    void readerIndex(int index);

    void resetReaderIndex();

    /**
     * Returns the number of readable bytes which is equal to {@code
     * (this.writerIndex - this.readerIndex)}.
     */
    int readableBytes();
}
